package com.tianji.StragyHttp.service.Impl;



import com.tianji.StragyHttp.dto.BaseCustomerAnalysisDTO;
import com.tianji.StragyHttp.enumr.CustomerAnalysisEnum;
import com.tianji.StragyHttp.service.ICustomerInsightService;
import com.tianji.StragyHttp.utils.SpringContextHolder;
import com.tianji.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import static com.tianji.StragyHttp.enumr.CustomerAnalysisEnum.PLATFORM_USER_ASSETS_OVERVIEW;

/**
 * Description: 客户洞察接口实现
 * Date: 2024/11/20
 *
 * @author Dawson
 */
@Service
@Slf4j
public class CustomerInsightServiceImpl implements ICustomerInsightService {

    @Override
    public <T> T getCustomerAnalysisData(BaseCustomerAnalysisDTO dto) {
        AnalysisStrategy<T> strategy = getAnalysisStrategy(dto.getCustomerAnalysisEnum());
        return strategy.analyze(dto);
    }

    @Override
    public Boolean exportCustomerAnalysisData(BaseCustomerAnalysisDTO dto) {
        AnalysisStrategy<T> strategy = getAnalysisStrategy(dto.getCustomerAnalysisEnum());
        return strategy.export(dto);
    }

    /**
     * 根据业务类型获取对应分析策略
     *
     * @param cusAnalysisEnum 业务类型枚举
     * @return 策略类
     */
    private <T> AnalysisStrategy<T> getAnalysisStrategy(CustomerAnalysisEnum cusAnalysisEnum) {
        switch (cusAnalysisEnum) {
            // 用户资产
            case PLATFORM_USER_ASSETS_OVERVIEW:
                return SpringContextHolder.getBean("customerInsightStrategy");
            //其他查询：todo
            default:
                throw new BizException("不存在的业务类型");
        }
    }
}
